package com.appspot.aliga.presentation;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
import com.appspot.aliga.Match;
import com.appspot.aliga.R;

import java.util.List;

public class MatchAdapter extends BaseAdapter {
    private List<Match> matches;
    private LayoutInflater inflater;

    public MatchAdapter(Context context, List<Match> list) {
        // Caches the LayoutInflater for quicker use
        this.inflater = LayoutInflater.from(context);

        this.matches = list;
    }

    public int getCount() {
        return this.matches.size();
    }

    public Object getItem(int position) {
        return this.matches.get(position);
    }

    public long getItemId(int position) {
        if (position < getCount() && position >= 0) {
            return position;
        }
        return 0;
    }

    public View getView(int position, View view, ViewGroup viewGroup) {
        if (view == null) { // If the View is not cached
            // Inflates the Common View from XML file
            view = this.inflater.inflate(R.layout.match_row, null);
        }

        Match match = matches.get(position);

        ((TextView)view.findViewById(R.id.matchRow_team1)).setText(match.getTeam1Name());
        ((TextView)view.findViewById(R.id.matchRow_team2)).setText(match.getTeam2Name());
        ((TextView)view.findViewById(R.id.matchRow_result)).setText(match.getTeam1Result() + ":" + match.getTeam2Result());


        return view;
    }
}
